package com.unicom.office.dataitem;

import com.unicom.office.type.NumberTypeItem;
import com.unicom.office.type.StringTypeItem;
import com.unicom.office.var.NumberVarItem;

public class NumberDataItem extends DataItem {
    public NumberDataItem(Object value, NumberVarItem config) {
        super(value, config);
    }

    public NumberDataItem(Object value){
        super(value, NumberTypeItem.INSTANCE.createVarItem("number"));
    }

    public NumberVarItem getConfig(){
        return (NumberVarItem)config;
    }

    public Number getValue(){
        return (Number) value;
    }

    public Double getDoubleValue(){
        return getValue().doubleValue();
    }

    public Integer getIntValue(){
        return getValue().intValue();
    }

    public Long getLongValue(){
        return getValue().longValue();
    }

    public static NumberDataItem create(Object value){
        return (NumberDataItem) NumberTypeItem.INSTANCE.createVarItem(null).createDataItem(value);
    }

    public String toString(){
        if(getDoubleValue()%1 == 0){
            return getLongValue().toString();
        }else{
            return getDoubleValue().toString();
        }
    }
}
